package com.qiezi.project.contract;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.qiezi.bean.CategoryTwoBean;
import com.qiezi.bean.DataBean;
import com.qiezi.bean.ResponseBean;
import com.qiezi.bean.VideoBean;
import com.qiezi.mvp.BaseMvpView;
import com.qiezi.mvp.BasePresenter;
import com.qiezi.project.adapter.CategoryAdapter;
import com.qiezi.project.adapter.RecommendAdapter;
import com.qiezi.util.Request;
import com.zhy.http.okhttp.request.RequestCall;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;


public class CategoryContract {
    public static class Presenter extends BasePresenter<View>{

        Map<String,String> params;
        private RequestCall cell;

        public void canceledCell(){
            if (cell != null)cell.cancel();
            mView.complete();
        }

        public void loadData(Integer id){
            if (params == null){
                params = new HashMap<>(1);
            }
            params.put("category_id",id.toString());
            if (cell != null) cell.cancel();
            cell = Request.post(Request.Api.getCategoryTwo, params, new Request.JsonCallback<DataBean<CategoryTwoBean>>(new TypeReference<DataBean<CategoryTwoBean>>(){}.getType()) {
                @Override
                public void onFailure(String msg) {
                    if (mView == null)return;
                    mView.showError(msg);
                }

                @Override
                public void onSueccess(ResponseBean<DataBean<CategoryTwoBean>> data) {
                    if (mView == null)return;
                    mView.onRefresh(data.getData().getList());
                }
            });

        }
    }

    public interface View extends BaseMvpView {
        void onRefresh(ArrayList<CategoryTwoBean> data);

    }
}